import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('127.0.0.1'))
channel = connection.channel()

channel.queue_declare(queue='hello2', durable=True)  # durable=True，声明可持久化队列

channel.basic_publish(exchange='',  # 简单模式
                      routing_key='hello2',  # 指定队列
                      body='Hello World',
                      properties=pika.BasicProperties(
                          delivery_mode=2  # 该数据需要持久化
                      ))

print(" [x] Sent 'Hello World'")
